﻿using MyCommunity.Models;
using MyCommunity.DataAccess;
using System.Collections.Generic;
using MyCommunity.BusinessLogic;
using System;

public class UserEventAttendanceService : IUserEventAttendanceService
{
    private readonly IUserEventAttendanceDAL dal;

    public UserEventAttendanceService(IUserEventAttendanceDAL dal)
    {
        this.dal = dal;
    }

    public List<UserEventAttendance> GetAllUsersForEvent(int eventId)
    {
        return this.dal.GetAllUsersForEvent(eventId);
    }

    public List<UserEventAttendance> GetAllUserEvents(int userId)
    {
        return this.dal.GetAllUserEvents(userId);
    }


    public void OptInEvent(User user, int eventId, String data)
    {
        UserEventAttendance userEventAttendance = this.dal.GetUserEvent(eventId, user.Id);

        if (userEventAttendance == null)
        {
            UserEventAttendance userEvent = new UserEventAttendance();
            userEvent.Attendance = data;
            userEvent.UserId = user.Id;
            userEvent.EventId = eventId;

            this.dal.RegisterUser(userEvent);
        }
        else
        {
            userEventAttendance.Attendance = data;
        }
        
    }
 

    public void SaveChanges()
    {
        this.dal.Save();
    }
}